package com.atguigu.gulimall.search.controller;

import com.atguigu.common.exception.BizCodeEnume;
import com.atguigu.common.to.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ProductSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author XB on 2021/11/23 0023.
 * @version 3.0
 */
@RestController
@RequestMapping("/ProductSearch")
@Slf4j
public class ProductSearchController {

	@Autowired
	private ProductSearchService productSearchService;

	@RequestMapping("/productSearch/getSkuEsmodel")
	public R getSkuEsmodel(@RequestBody List<SkuEsModel> skuEsModelList) throws IOException {
		boolean b=false;

		try {
			b = productSearchService.getSkuEsmodel(skuEsModelList);
		} catch (IOException e) {
			log.error("商品上架失败：{}",e);
			return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
		}

		if (b){
			return R.ok();
		}else {
			return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
		}
	}
}
